package artid.com.arttogoa.adapter;

import java.util.List;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.view.ViewGroup;

import artid.com.arttogoa.fragment.MicroscopicMapFragment;
import artid.com.arttogoa.keeponrecord.ArtRecordActivity;
import artid.com.arttogoa.parser.MapBean;
import artid.com.arttogoa.parser.MicMapBean;
import artid.com.arttogoa.task.CallbackSky;

/**
 * ClassName:MatchFragmentAdapter <br/>
 * Function: 项目页适配器<br/>
 * Reason: 解决项目页标签可以左右滑动的功能 <br/>
 * Date: 2014-2-25 下午4:00:34 <br/>
 * 
 * @author ybq
 * @version
 * @since JDK 1.6
 * @see
 */
public class MicFragmentAdapter extends FragmentStatePagerAdapter {

	private List<MicMapBean> mList;
	private CallbackSky call;
	/** 上传模式 */
	private String updataType;

	public MicFragmentAdapter(FragmentManager fm, CallbackSky call,
			String updataType) {
		super(fm);
		this.call = call;
		this.updataType = updataType;
	}

	public void setData(List<MicMapBean> list) {
		mList = list;
		notifyDataSetChanged();
	}

	@Override
	public Fragment getItem(int position) {
		return getFragments(position);
	}

	@Override
	public Object instantiateItem(ViewGroup group, int position) {
		return super.instantiateItem(group, position);
	}

	private Fragment getFragments(int position) {
		MicroscopicMapFragment fragment = new MicroscopicMapFragment(call);
		fragment.setArguments(getBundle(position));
		return fragment;
	}

	private Bundle getBundle(int position) {
		Bundle bundle = new Bundle();
		if (updataType.equals(ArtRecordActivity._PHONE)) {
			MicMapBean mmb = mList.get(position);
			MapBean data = new MapBean();
			data.setUrl(mmb.getImage());
			data.setId(position);
			bundle.putSerializable("data", data);
		} else {
			MicMapBean mmb = mList.get(position / 2);
			MapBean data = new MapBean();
			if ((position) % 2 == 1) {
				data.setUrl(mmb.getImage200());
			} else {
				data.setUrl(mmb.getImage());
			}
			data.setId(position);
			bundle.putSerializable("data", data);
		}

		return bundle;
	}

	@Override
	public int getCount() {
		if (updataType.equals(ArtRecordActivity._PHONE)) {
			return null == mList ? 0 : mList.size();
		} else {
			return null == mList ? 0 : mList.size() * 2;
		}
	}

	@Override
	public int getItemPosition(Object object) {
		return POSITION_NONE;
	}
}
